package com.meilai.project.controller.mini;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.entity.system.Dictionary;
import com.meilai.project.entity.system.User;
import com.meilai.project.service.system.DictionaryService;
import com.meilai.project.service.system.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "小程序-通用")
@RequestMapping("api/mini/common")
@RestController
public class MiniCommonController {

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private UserService userService;

    @GetMapping("/dict/list_all3rd_bycode")
    @ApiOperation("通过code获取下级字典列表")
    public ApiResult<List<Dictionary>> listAll3rdBycode(@RequestParam(value = "code") String code) {
        return ApiResult.ok(dictionaryService.listByCode(code));
    }

    @GetMapping("/user/allUserList")
    @ApiOperation("获取所有的用户")
    public ApiResult<List<User>> allUserList() {
        List<User> list = userService.list(Wrappers.<User>lambdaQuery().eq(User::getStatus, 1).isNull(User::getDeleted_at));
        list.forEach(item -> {
            item.setPassword("");
        });
        return ApiResult.ok(list);
    }

}
